ExtendedMarkdown.pluginName   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
dl 0
loc 3
rs 10
1
/*
2
 * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
3
 *
4
 *  Copyright (C) 2019 - 2022 Jan Böhmer (https://github.com/jbtronics)
5
 *
6
 *  This program is free software: you can redistribute it and/or modify
7
 *  it under the terms of the GNU Affero General Public License as published
8
 *  by the Free Software Foundation, either version 3 of the License, or
9
 *  (at your option) any later version.
10
 *
11
 *  This program is distributed in the hope that it will be useful,
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 *  GNU Affero General Public License for more details.
15
 *
16
 *  You should have received a copy of the GNU Affero General Public License
17
 *  along with this program.  If not, see <https://www.gnu.org/licenses/>.
18
 */
19
20
import { Plugin } from 'ckeditor5/src/core';
21
import GFMDataProcessor from '@ckeditor/ckeditor5-markdown-gfm/src/gfmdataprocessor';
22
23
const ALLOWED_TAGS = [
24
	//Common elements
25
	'sup',
26
	'sub',
27
	'u',
28
	'kbd',
29
	'mark',
30
	'ins',
31
	'small',
32
	'abbr',
33
	'br',
34
35
	//Block elements
36
	'span',
37
	'p',
38
	'img',
39
40
41
42
	//These commands are somehow ignored: TODO
43
	'left',
44
	'center',
45
	'right',
46
];
47
48
/**
49
 * The GitHub Flavored Markdown (GFM) plugin with added HTML tags, which are kept in the output. (inline mode)
50
 *
51
 */
52
export default class ExtendedMarkdown extends Plugin {
53
54
	/**
55
	 * @inheritDoc
56
	 */
57
	constructor( editor ) {
58
		super( editor );
59
60
		editor.data.processor = new GFMDataProcessor( editor.data.viewDocument );
61
		for (const tag of ALLOWED_TAGS) {
62
			editor.data.processor.keepHtml(tag);
63
		}
64
	}
65
66
	/**
67
	 * @inheritDoc
68
	 */
69
	static get pluginName() {
70
		return 'Markdown';
71
	}
72
}
73